package com.LeeCode;

/**
 * 斐波那契数列
 */

public class Code509 {
    public static void main(String[] args) {
        System.out.println(new Code509().fib(4));
    }

    public int fib(int n) {
        if (n == 0) return 0;
        if (n == 1) return 1;
        int a = 0, b = 1, ans = 0;
        for (int i = 2; i <= n; i++) {
            ans = a + b;
            a = b;
            b = ans;
        }
        return ans;
    }
}
